﻿// Boundary class for prompt users 
/*2012-03-31 Modified by Syrings
Only for display the event description and the result of the event
Also, get the input and put this value to event controller
Remove some "get set" methods
Edited method: displaySelectedEvent(), showQuestion(),showMC()
Created method: showResult(), getPlayerAns()
*/
//********************************************************
// Modified by Ming
// Date: 13 April 2012
// Changes: Check the input if it is not a number

package event;

import player.*;
import card.EventCard;
import java.util.Scanner;

public class EventWindow {
	private Player player;
	private EventCard pickedEvent;
	private EventController eventController;
	
	public EventWindow(Player player){
		this.player = player;
		eventController = new EventController();
	}
	
	public void greet() {
		System.out.println("You just step on the Event Cell!");
		System.out.println("Welcome to the Event Window");
		
		// Prompt user to press Enter
		System.out.println("Press Enter to pick a random Event: ");
		Scanner keyboard = new Scanner(System.in);
		keyboard.nextLine();
			
		eventController.RandomEvent(player);
	}
		
	/**show the event card info*/
	public void showPickedEventInfo(int diceNo){
		pickedEvent = eventController.getSelectedEvent(diceNo);
		System.out.println("You have picked Event " + (pickedEvent.getEventID()+1)); 
		String eventQuestion = pickedEvent.getQuestion();
		String eventMC = pickedEvent.getEventMC();
		System.out.println(eventQuestion);
		System.out.println(eventMC);
	}
	
	public int getPlayerAns(){
		int userAns=0;
		boolean valid = false;

		do{
			System.out.println("\nNow answer the question:");
			Scanner ss = new Scanner(System.in);
			if (ss.hasNextInt()) 
			{
				userAns = ss.nextInt();
				if (validPlayerNo(userAns))
					valid=true;					
			}
		}
		while (!valid);
		return userAns;
	}
	
	public boolean validPlayerNo(int userAns){
		if(userAns <0 ||  userAns > pickedEvent.getScore().length) return false;
		else return true;
	}
	
	public void showResult(int userAns,Player player){
		//EventController eC = new EventController();
		int pointsChange = eventController.marker(userAns, pickedEvent);
		
		// update user points
		eventController.updateSEPoints(player, pointsChange);
		//player = eventController.gettemPlayer();
		
		//display the result and end of the event
		PlayerIO print = new PlayerIO();
		print.updateSEValue(player);
		//print.printSinglePlayerInfo(player);
		System.out.println("Event Stop here.");
		System.out.println("**************************************");
	}

}
